﻿CREATE FUNCTION QIC.FormatArg(@Value VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN

	IF @Value = 'NULL' RETURN @Value
	IF '''' + REPLACE(@Value, '''','') + '''' = @Value RETURN @Value
	IF '[' + REPLACE(REPLACE(@Value, '[','') ,']','') + ']' = @Value RETURN @Value
	IF LEFT(@Value,1) = '@' RETURN @Value

	RETURN QUOTENAME(@Value)

END

